package com.web.hawaste.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.web.hawaste.entity.SysUserRole;
import com.web.hawaste.mapper.SysUserRoleMapper;
import com.web.hawaste.service.ISysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Suzy
 * @since 2022-09-26
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    /**
     * 方法名: deleteBatch
     * 描述: 根据角色ID和人员的id列表删除已选人员
     *
     * @param rid 角色ID
     * @param ids id列表
     * @return int
     * @date 2022/10/12 22:42
     * @auther YangSuzy
     **/
    @Override
    public int deleteBatch(long rid, Long[] ids) {
        QueryWrapper<SysUserRole> query = new QueryWrapper<>();
        query.eq("role_id", rid)
                .in("user_id", ids);
        return baseMapper.delete(query);
    }

    /**
     * 方法名: insertBatch
     * 描述: 根据角色Id和人员id列表添加待选人员
     *
     * @param rid 角色id
     * @param ids 人员id列表
     * @return boolean
     * @date 2022/10/12 22:50
     * @auther YangSuzy
     **/
    @Override
    public boolean insertBatch(long rid, List<Long> ids) {
        ArrayList<SysUserRole> sysUserRoles = new ArrayList<>();
        ids.forEach(aLong -> {
            SysUserRole userRole = new SysUserRole();
            userRole.setRoleId(rid);
            userRole.setUserId(aLong);
            sysUserRoles.add(userRole);
        });
        return saveBatch(sysUserRoles);
    }
}
